import Vue from "vue"

import Router from "vue-router"
// import Home from "@/views/Home"
import Regster from "@/views/Regster"
import category from "@/views/Category"
import shopingcar from "@/views/Shopingcar"
// import My from "@/views/My"
import DetailPage from "@/views/DetailPage"
import SearchPage from '@/views/Searchpage'
import Searchgoods from '@/views/SearchGoods'
// import ZhucePage from '@/views/ZhucePage'
import CateBrand from '@/views/Cate-Brand'
import Setvue from '@/views/set'
import Confimgoods from '@/views/Confimgoods'
import useraderss from '@/views/Useraderss'
import goodslook from '@/views/GoodLook'
import useraddaderss from '@/views/UserAddaderss'
import Updateaderss from '@/views/UpdateAdress'
import AboutMy from '@/views/AboutMy'
import Collect from '@/views/Collect'
import AddressChoice from '@/views/AddressChoice'
// import ZhuceIndex from '@/components/ZhuceIndex'
// import Zhucecode from '@/components/ZhuCecode'
// import ZhuCePwd from '@/components/ZhuCePwd'
//注册分组懒加载
const ZhucePage = () => import(/* webpackChunkName: 'zhuce' */ '@/views/ZhucePage')
const ZhuceIndex = () => import(/* webpackChunkName: 'zhuce' */ '@/components/ZhuceIndex')
const Zhucecode = () => import(/* webpackChunkName: 'zhuce' */ '@/components/ZhuCecode')
const ZhuCePwd = () => import(/* webpackChunkName: 'zhuce' */ '@/components/ZhuCePwd')
//插件安装到vue里
Vue.use(Router)
 const router = new Router({
    routes:[
        {
            path:"/",
            component:Home=> require(["@/views/Home"],Home),
        },
        {
            path:"/reg",
            component:Regster
        },
        {
            path:"/category",
            component:category,
           
        },
        {
            path:"/shopingcar",
            component:shopingcar,
            beforeEnter:(to,from,next)=>{
                if(localStorage.getItem("token")){
                    next()
                }else{
                    next("/reg")
                }
            }
        },
        {
            path:"/confimgods",
            component:Confimgoods
        },
        {
            path:"/my",
            // 直接是一个函数
            component:() => import('@/views/My'),
            
        },
        {
            path:"/DetailPage/:id",
            component:DetailPage
        },
        {
            path:"/Result/:phone/:brand",
            component:CateBrand
        },
        {
            path:"/search",
            component:SearchPage
        },
        {
            path:"/searchResult/:keyword",
            component:Searchgoods
        },
        {
            path:"/set",
            component:Setvue
        },
        {
            path:"/useraderss",
            component:useraderss,
            beforeEnter:(to,from,next)=>{
                if(localStorage.getItem("token")){
                    next()
                }else{
                    next("/reg")
                }
            }
        },
        {
            path:"/useraddaderss",
            component:useraddaderss
        },
        {
            path:"/updateaderss",
            component:Updateaderss
            
        },
        {
            path:"/goodslook",
            component:goodslook,
            beforeEnter:(to,from,next)=>{
                if(localStorage.getItem("token")){
                    next()
                }else{
                    next("/reg")
                }
            }
        },
        {
            path:"/zhuce",
            component:ZhucePage,
            children:[
           {
                path:"/zhuce/index",
                component:ZhuceIndex
            },
           {
                path:"/zhuce/code",
                component:Zhucecode
            },
           {
                path:"/zhuce/pwd",
                component:ZhuCePwd
            },
        ]
        },
        {
            path:"/aboutmy",
            component:AboutMy
        },
        {
            path:"/collect",
            component:Collect
        },
        {
            path:"/addresschoice",
            component:AddressChoice
        },

       
    ], 
})

export default router
